<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<div id="content" style="display: none;">

</div>
<script>
    $(document).ready(function () {
        $("#content").css('display', 'block')
    });
    $.ajax({
        url: '/getUserInfo',
        type: 'get',
        dataType: 'json',
        success(res) {
            console.log(res);
            if (res.userName === undefined) {
                return $('#content').html(` <button onclick="window.location.href='/register'">登录</button>
           <button  onclick="window.location.href='/login'">注册</button> `)
            }
            $("#content").html(`<h1>欢迎</h1>
                                <div>用户名: <span id="userName"></span></div>
                                <div>昵称: <span id="nickName"></span></div>
                                <h1>的大爷光临</h1>
                                <div><button onclick="esc()">退出登录</button></div>`)
            $('#userName').html(res.userName);
            $('#nickName').html(res.nickName);
        }
    })

    function esc() {
        $.ajax({
            url: '/esc',
            type: 'get',
            success() {
                window.location.href = "/"
            }
        })
    }
</script>
</body>
</html>
